手写字迹模拟器

本软件采用python开发 UI部分使用tkinter

下载

源码

windows10可执行文件

演示图下面是演示图

1704116276746

1704115574321

源码演示

下面是源码(不能直接用请下载完整包)

from PIL import Image, ImageFont from handright import Template, handwrite import docx import re from tkinter import * from tkinter import filedialog import tkinter as tk from PIL import ImageTk, Image import webbrowser import threading import os import tkinter.messagebox import uuid window = tk.Tk() window.resizable(False, False) window.geometry('1200x1000+350+0') window.title("hello world 手写模拟器 制作人:澪") window.iconbitmap('tu\icon.ico') def beijingtu(): root=tk.Tk() root.resizable(False,False) root.geometry("400x350+100+500") root.title("hello world") root.iconbitmap("tu\icon.ico") tk.Label(root, text="""x轴(横坐标)""").place(x=40,y=150,anchor='nw') tk.Label(root, text="""y轴(纵坐标)""").place(x=40,y=180,anchor='nw') entry14= tk.Entry(root,width=20) entry14.place(x=120,y=150,anchor='nw') entry15= tk.Entry(root,width=20) entry15.place(x=120,y=180,anchor='nw') def xyvy(): global vr14 global vr15 vr14=entry14.get() vr15=entry15.get() file_1=open("tu\\peizhi\\x.txt",mode="w") file_2=open("tu\\peizhi\\y.txt",mode="w") file_1.write(vr14) file_2.write(vr15) tk.Button(root,text='确定',command=xyvy).place(x=150,y=210,anchor='nw') tk.Label(root, text="""注:坐标的原点在左上角,\nx轴数字越大图片越靠左,\ny轴数字越大图片越靠下,\n全部填写完后关闭程序然后重新打开""").place(x=80,y=250,anchor='nw') def zhuti(): global bjt bjt=filedialog.askopenfilename(filetypes=[("PNG",".png")]) tk.Label(root, text=bjt).place(x=30,y=120,anchor='nw') file_3=open("tu\\peizhi\\t.txt",mode="w") file_3.write(bjt) tk.Button(root,text='选择背景图',command=zhuti).place(x=150,y=85,anchor='nw') root.mainloop() try: try: classes_path = os.path.expanduser("tu\\peizhi\\x.txt") with open(classes_path,'r',encoding = 'UTF-8') as f: da = f.readlines() da = [c.strip() for c in da] except: classes_path = os.path.expanduser("tu\\peizhi\\x.txt") with open(classes_path,'r',encoding = 'gbk') as f: da = f.readlines() da = [c.strip() for c in da] try: classes_path = os.path.expanduser("tu\\peizhi\\y.txt") with open(classes_path,'r',encoding = 'UTF-8') as f: da1 = f.readlines() da1 = [c.strip() for c in da1] except: classes_path = os.path.expanduser("tu\\peizhi\\y.txt") with open(classes_path,'r',encoding = 'gbk') as f: da1 = f.readlines() da1 = [c.strip() for c in da1] try: classes_path = os.path.expanduser("tu\\peizhi\\t.txt") with open(classes_path,'r',encoding = 'UTF-8') as f: da1 = f.readlines() da1 = [c.strip() for c in da1] except: classes_path = os.path.expanduser("tu\\peizhi\\t.txt") with open(classes_path,'r',encoding = 'gbk') as f: da2 = f.readlines() da2 = [c.strip() for c in da2] xzuobiao=da[0] yzuobiao=da1[0] zhuti=da2[0] image=Image.open(zhuti) photo=ImageTk.PhotoImage(image) lab =tk.Label(window,image=photo).place(x=xzuobiao,y=yzuobiao,anchor='nw') except: image=Image.open("tu\e5.png") photo=ImageTk.PhotoImage(image) lab =tk.Label(window,image=photo).place(x=460,y=440,anchor='nw') entry = tk.Entry(window,width=20) entry.place(x=0,y=30,anchor='nw') entry1 = tk.Entry(window,width=20) entry1.place(x=0,y=54,anchor='nw') entry2 = tk.Entry(window,width=20) entry2.place(x=0,y=78,anchor='nw') entry3 = tk.Entry(window,width=20) entry3.place(x=0,y=102,anchor='nw') entry4 = tk.Entry(window,width=20) entry4.place(x=0,y=126,anchor='nw') entry5 = tk.Entry(window,width=20) entry5.place(x=0,y=150,anchor='nw') entry6 = tk.Entry(window,width=20) entry6.place(x=0,y=174,anchor='nw') entry7 = tk.Entry(window,width=20) entry7.place(x=0,y=198,anchor='nw') entry8 = tk.Entry(window,width=20) entry8.place(x=0,y=222,anchor='nw') entry9 = tk.Entry(window,width=20) entry9.place(x=0,y=246,anchor='nw') entry10 = tk.Entry(window,width=20) entry10.place(x=0,y=270,anchor='nw') entry11 = tk.Entry(window,width=20) entry11.place(x=0,y=294,anchor='nw') entry12 = tk.Entry(window,width=20) entry12.place(x=0,y=318,anchor='nw') def callback(): global fileName fileName =filedialog.askopenfilename(filetypes=[("TTF",".ttf")]) tk.Label(window, text=fileName).place(x=0,y=370,anchor='nw') def tupian(): global beijing beijing =filedialog.askopenfilename(filetypes=[("JPG",".jpg")]) tk.Label(window, text=beijing).place(x=0,y=430,anchor='nw') def dk(): global wb wb =filedialog.askopenfilename(filetypes=[("DOCX",".docx")]) tk.Label(window, text=wb).place(x=70,y=5,anchor='nw') def ysdk(): global yswb yswb =filedialog.askopenfilename(filetypes=[("DOCX",".docx")]) tk.Label(window, text=yswb).place(x=900,y=100,anchor='nw') def gengxin(): webbrowser.open_new_tab('https://wwgv.lanzout.com/b037tgoid') def v0(): try: tkinter.messagebox.showwarning(title = '提示',message='程序会自动将模拟的文字保存为jpg格式的图片,不用担心一张图片放不下所有文字程序可以生成多张图片(点击确认后程序会弹出预览界面,关闭预览后会自动保存图片)最重要的一点不要一直开着预览界面否则会导致程序卡顿') vr0=entry.get() vr0=int(vr0) vr1=entry1.get() vr1=float(vr1) vr2=entry2.get() vr2=float(vr2) vr3=entry3.get() vr3=float(vr3) vr4=entry4.get() vr4=float(vr4) vr5=entry5.get() vr5=float(vr5) vr6=entry6.get() vr6=float(vr6) vr7=entry7.get() vr7=float(vr7) vr8=entry8.get() vr8=float(vr8) vr9=entry9.get() vr9=float(vr9) vr10=entry10.get() vr10=float(vr10) vr11=entry11.get() vr11=float(vr11) vr12=entry12.get() vr12=float(vr12) def get_text(file_path, indent_size=4): doc = docx.Document(file_path) texts = [] indent = '' for i in range(0, indent_size): indent = indent + ' ' for paragraph in doc.paragraphs: texts.append(indent + paragraph.text) return '\n'.join(texts) text = get_text(wb) template = Template( background=Image.open(beijing), font=ImageFont.truetype(fileName, vr0), line_spacing=vr1, fill=0, left_margin=vr2, top_margin=vr3, right_margin=vr4, bottom_margin=vr5, word_spacing=vr6, line_spacing_sigma=vr7, font_size_sigma=vr8, word_spacing_sigma=vr9, end_chars=", : 。 、", perturb_x_sigma=vr10, perturb_y_sigma=vr11, perturb_theta_sigma=vr12, ) images = handwrite(text, template) for i, im in enumerate(images): assert isinstance(im, Image.Image) im.show() im.save("{}.jpg".format(i)) except: tkinter.messagebox.showwarning(title = '提示',message='检测到您的字体信息配置有误,\n开始尝试自动修正……但不保证成功…………QAQ') def get_text(file_path, indent_size=4): doc = docx.Document(file_path) texts = [] indent = '' for i in range(0, indent_size): indent = indent + ' ' for paragraph in doc.paragraphs: texts.append(indent + paragraph.text) return '\n'.join(texts) text = get_text(wb) template = Template( background=Image.open(beijing), font=ImageFont.truetype(fileName, size=100), line_spacing=100, fill=0, left_margin=10, top_margin=10, right_margin=10, bottom_margin=10, word_spacing=0, line_spacing_sigma=0, font_size_sigma=0, word_spacing_sigma=0, end_chars=", : 。 、", perturb_x_sigma=0, perturb_y_sigma=0, perturb_theta_sigma=0.01, ) images = handwrite(text, template) for i, im in enumerate(images): assert isinstance(im, Image.Image) im.show() im.save("{}.jpg".format(i)) def yvshe(): tkinter.messagebox.showwarning(title = '提示',message='程序会自动将模拟的文字保存为jpg格式的图片,不用担心一张图片放不下所有文字程序可以生成多张图片(点击确认后程序会弹出预览界面,关闭预览后会自动保存图片)最重要的一点不要一直开着预览界面否则会导致程序卡顿') global beijing beijing =filedialog.askopenfilename(filetypes=[("TXT",".txt")]) try: classes_path = os.path.expanduser(beijing) with open(classes_path,'r',encoding = 'UTF-8') as f: data = f.readlines() data = [c.strip() for c in data] except: classes_path = os.path.expanduser(beijing) with open(classes_path,'r',encoding = 'gbk') as f: data = f.readlines() data = [c.strip() for c in data] def get_text(file_path, indent_size=4): doc = docx.Document(file_path) texts = [] indent = '' for i in range(0, indent_size): indent = indent + ' ' for paragraph in doc.paragraphs: texts.append(indent + paragraph.text) return '\n'.join(texts) text = get_text(yswb) zitidaxiao=data[0] zitidaxiao=int(zitidaxiao) hangjianjv=data[1] hangjianjv=float(hangjianjv) zuobianjv=data[2] zuobianjv=float(zuobianjv) shangbianjv=data[3] shangbianjv=float(shangbianjv) youbianjv=data[4] youbianjv=float(youbianjv) xiabianjv=data[5] xiabianjv=float(xiabianjv) zifujianjv=data[6] zifujianjv=float(zifujianjv) hangjianjvsuijibianhua=data[7] hangjianjvsuijibianhua=float(hangjianjvsuijibianhua) zitidaxiaosuijibianhua=data[8] zitidaxiaosuijibianhua=float(zitidaxiaosuijibianhua) zijianjvsuijiraodong=data[9] zijianjvsuijiraodong=float(zijianjvsuijiraodong) bihuahengxiangraodong=data[10] bihuahengxiangraodong=float(bihuahengxiangraodong) bihuazongxiangrandong=data[11] bihuazongxiangrandong=float(bihuazongxiangrandong) bihuaxuanzhuangpiaoyi=data[12] bihuaxuanzhuangpiaoyi=float(bihuaxuanzhuangpiaoyi) zt=data[13] yst=data[14] template = Template( background=Image.open(yst), font=ImageFont.truetype(zt, size=zitidaxiao), line_spacing=hangjianjv, fill=0, left_margin=zuobianjv, top_margin=shangbianjv, right_margin=youbianjv, bottom_margin=xiabianjv, word_spacing=zifujianjv, line_spacing_sigma=hangjianjvsuijibianhua, font_size_sigma=zitidaxiaosuijibianhua, word_spacing_sigma=zijianjvsuijiraodong, end_chars=", : 。 、", perturb_x_sigma=bihuahengxiangraodong, perturb_y_sigma=bihuazongxiangrandong, perturb_theta_sigma=bihuaxuanzhuangpiaoyi, ) images = handwrite(text, template) for i, im in enumerate(images): assert isinstance(im, Image.Image) im.show() im.save("{}.jpg".format(i)) def bug(): from email.mime.text import MIMEText from email.header import Header from smtplib import SMTP_SSL vr13=entry13.get() vr13=(vr13) host_server = '' #写自己邮箱的smtp服务器 sender_qq = '' #写自己的邮箱地址 pwd = '' #授权码 sender_qq_mail = '' #写自己的邮箱地址 receiver = '' #收件箱地址 mail_content = vr13 tkinter.messagebox.showwarning(title = 'bug',message='唔……你发现了什么bug呢————不过还是谢谢了') mail_title = '投票' smtp = SMTP_SSL(host_server) smtp.set_debuglevel(1) smtp.ehlo(host_server) smtp.login(sender_qq, pwd) msg = MIMEText(mail_content, "plain", 'utf-8') msg["Subject"] = Header(mail_title, 'utf-8') msg["From"] = sender_qq_mail msg["To"] = receiver smtp.sendmail(sender_qq_mail, receiver, msg.as_string()) smtp.quit() def jibenxinxi(): import wmi c = wmi.WMI() for physical_disk in c.Win32_DiskDrive(): e=physical_disk.SerialNumber a="您的硬盘序列号为:" b=a+e tk.Label(window, text=b).place(x=940,y=550,anchor='nw') for cpu in c.Win32_Processor(): e1=cpu.ProcessorId.strip() a1="您的cpu序列号为:" b1=a1+e1 tk.Label(window, text=b1).place(x=940,y=570,anchor='nw') for board_id in c.Win32_BaseBoard(): e2=board_id.SerialNumber a2="您的主板序列号为:" b2=a2+e2 tk.Label(window, text=b2).place(x=940,y=590,anchor='nw') zitidaxiao = """字体大小(请填写整数,推荐100)""" wenbben0 = tk.Label(window, text=zitidaxiao).place(x=145,y=30,anchor='nw') hangjianjv = """行间距(不要太小根据字体大小而定,推荐:100)""" wenbben1 = tk.Label(window, text=hangjianjv).place(x=145,y=54,anchor='nw') zuobianjv = """左边距(根据纸张来顶,单位:像素)""" wenbben2 = tk.Label(window, text=zuobianjv).place(x=145,y=78,anchor='nw') shangbianjv = """上边距(根据纸张来顶,单位:像素)""" wenbben3 = tk.Label(window, text=shangbianjv).place(x=145,y=102,anchor='nw') youbianjv = """右边距(根据纸张来顶,单位:像素)""" wenbben4 = tk.Label(window, text=youbianjv).place(x=145,y=126,anchor='nw') xiabianjv = """下边距(根据纸张来顶,单位:像素)""" wenbben5 = tk.Label(window, text=xiabianjv).place(x=145,y=150,anchor='nw') zifubianjv = """字符间距(单位:像素,0就可以)""" wenbben6 = tk.Label(window, text=zifubianjv).place(x=145,y=174,anchor='nw') hangjianjvsuijiraodong = """行间距随机扰动(单位:像素,0就可以)""" wenbben7 = tk.Label(window, text=hangjianjvsuijiraodong).place(x=145,y=198,anchor='nw') zitidaxiaosuijiraodong = """字体大小随机扰动(单位:像素,0就可以)""" wenbben8 = tk.Label(window, text=zitidaxiaosuijiraodong).place(x=145,y=222,anchor='nw') zijianjvsuijiraodong = """字间距随机扰动(单位:像素,0就可以)""" wenbben9 = tk.Label(window, text=zijianjvsuijiraodong).place(x=145,y=246,anchor='nw') bihuahengxiangsuijiraodong = """笔画横向漂移随机扰动(单位:像素,0就可以)""" wenbben10 = tk.Label(window, text=bihuahengxiangsuijiraodong).place(x=145,y=270,anchor='nw') bihuazongxiangsuijiraodong = """笔画纵向漂移随机扰动(单位:像素,0就可以)""" wenbben11 = tk.Label(window, text=bihuazongxiangsuijiraodong).place(x=145,y=294,anchor='nw') buhuaxuanzhuang = """笔画选装漂移随机扰动(0.01就差不多了)""" wenbben12 = tk.Label(window, text=buhuaxuanzhuang).place(x=145,y=318,anchor='nw') tk.Button(window,text='确定',command=v0).place(x=0,y=469,anchor='nw') tk.Button(window,text='选择字体',command=callback).place(x=0,y=340,anchor='nw') tk.Button(window,text='选择背景图',command=tupian).place(x=0,y=400,anchor='nw') tk.Button(window,text='选择word',command=dk).place(x=0,y=0,anchor='nw') tk.Label(window, text="""|\n|\n|\n|\n|\n|\n手\n动\n模\n式\n|\n|\n|\n|\n|\n|\n手\n动\n模\n式\n|\n|\n|\n|\n|\n|\n手\n动\n模\n式\n|\n|\n|\n|\n|\n|""").place(x=430,y=5,anchor='nw') tk.Label(window, text="""———————手—动—模—式———————手—动—模—式——————""").place(x=0,y=610,anchor='nw') def yvshemoshi(): tk.Label(window, text="""|\n|\n|\n|\n|\n|\n预\n设\n模\n式\n|\n|\n|\n|\n|\n|""").place(x=880,y=5,anchor='nw') tk.Label(window, text="""这里是预设模式,\n一定要先选择word文档,\n然后在选择预设文件""").place(x=950,y=5,anchor='nw') tk.Label(window, text="""—————————预—设—模—式—————————""").place(x=898,y=265,anchor='nw') tk.Button(window,text='选择word',command=ysdk).place(x=980,y=70,anchor='nw') tk.Button(window,text='选择预设文件',command=yvshe).place(x=970,y=130,anchor='nw') def BG(): global wenbben13 global entry13 tk.Label(window, text="""|\n|\n|\n|\n|\n|\nB\nU\nG\n反\n馈\n|\n|\n|\n|\n|""").place(x=820,y=720,anchor='nw') tk.Label(window, text="""——————B———U———G———反———馈————————""").place(x=825,y=720,anchor='nw') tk.Button(window,text='发送',command=bug).place(x=860,y=895,anchor='nw') bugfankui = """BUG反馈(不要随便发哦……QAQ)""" wenbben13 = tk.Label(window, text=bugfankui).place(x=865,y=870,anchor='nw') entry13 = tk.Entry(window,width=20) entry13.place(x=900,y=900,anchor='nw') def gx(): tk.Button(window,text='更新',command=gengxin).place(x=30,y=895,anchor='nw') tk.Label(window, text="""密码是:3w1s""").place(x=30,y=935,anchor='nw') tk.Label(window, text="""|\n|\n|\n|\n|\n|\n更\n|\n新\n|\n|\n|\n|\n|""").place(x=250,y=750,anchor='nw') tk.Label(window, text="""—————更——————新——————""").place(x=0,y=745,anchor='nw') tk.Label(window, text="""——拓————展————模————块——————""").place(x=940,y=400,anchor='nw') tk.Label(window, text="""——拓————展————模————块——————""").place(x=940,y=520,anchor='nw') tk.Label(window, text="""|\n|\n拓\n展\n模\n块\n|\n|""").place(x=935,y=400,anchor='nw') tk.Button(window,text='更新模块',command=gx).place(x=960,y=450,anchor='nw') tk.Button(window,text='激活预设模式',command=yvshemoshi).place(x=980,y=490,anchor='nw') tk.Button(window,text='问题与反馈',command=BG).place(x=1020,y=450,anchor='nw') tk.Button(window,text='查询基本信息',command=jibenxinxi).place(x=1080,y=490,anchor='nw') tk.Button(window,text='更改背景图',command=beijingtu).place(x=1100,y=450,anchor='nw') window.mainloop()